sunsetwx / sunburst.js

This library provides authorization handling and methods for accessing the Sunburst API.
https://sunburst.sunsetwx.com/v1/docs
ISC License
8 stars 1 forks source link

React-native support? #1

Closed GowthamGr closed 5 years ago

GowthamGr commented 6 years ago

Please explain me with working example for react native.

umpc commented 6 years ago

The readme has what you're looking for. Use the import statement for React Native and then any of the examples.

GowthamGr commented 6 years ago

Thank you @umpc .

screenshot_1533644429

Can you please help to solve this.

umpc commented 6 years ago

I can't help unless you share the version of React Native that you're using and provide all of the relevant code for reproducing the issue.

If you post that info, I would be glad to help.

GowthamGr commented 6 years ago

{ "name": "react_native_chart_kit", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.4.1", "react-native": "0.56.0", "react-native-calendar-heatmap": "^0.1.2", "react-native-chart-kit": "^1.1.5", "react-native-heatmap": "^0.1.2", "sunburst.js": "^2.1.1" }, "devDependencies": { "babel-jest": "23.4.2", "babel-preset-react-native": "5.0.2", "jest": "23.4.2", "react-test-renderer": "16.4.1" }, "jest": { "preset": "react-native" } }

//This is my code sunFunc=async()=>{ try { const sunburst = new SunburstJS();

      const session = await sunburst.createSession({
          email: 'example@example.com',
          password: 'hunter2',
          type: 'permanent',
          scope: ['predictions']
      });
      console.log(session);
  } catch (ex) {
      // Handle general network or parsing errors.
      return console.error(ex);
  }

};

preFunc=async ()=>{ try { const now = new Date(); const thisTimeTomorrow = now.setDate(now.getDate() + 1); const resp = await sunburst.batchQuality([ { geo: [40.7933949, -77.8600012], type: 'sunrise' }, { geo: [40.7933949, -77.8600012], type: 'sunset' }, { geo: [40.7933949, -77.8600012], type: 'sunrise', after: thisTimeTomorrow }, { geo: [40.7933949, -77.8600012], type: 'sunset', after: thisTimeTomorrow } ]); resp.forEach(({ collection, error }) => { if (error) { // Handle individual query errors separately, // as some queries may have still succeeded. return console.error(error); } collection.features.forEach(({ properties }) => { console.log(properties); }); }); } catch (ex) { // Handle general network or parsing errors. return console.error(ex); }};

umpc commented 6 years ago

I can't see where you import the library.

GowthamGr commented 6 years ago

//Yes i imported following

import SunburstJS from 'sunburst.js';

GowthamGr commented 6 years ago

//App.js file import React, {Component} from 'react'; import {Dimensions,Platform, StyleSheet, Text, View} from 'react-native'; import SunburstJS from 'sunburst.js'; //const SunburstJS = require('sunburst.js');

export default class App extends Component { render() { return (

);

}

sunFunc=async()=>{ try { const sunburst = new SunburstJS();

      const session = await sunburst.createSession({
          email: 'example@example.com',
          password: 'hunter2',
          type: 'permanent',
          scope: ['predictions']
      });
      console.log(session);
  } catch (ex) {
      // Handle general network or parsing errors.
      return console.error(ex);
  }

};

preFunc=async ()=>{ try { const now = new Date(); const thisTimeTomorrow = now.setDate(now.getDate() + 1); const resp = await sunburst.batchQuality([ { geo: [40.7933949, -77.8600012], type: 'sunrise' }, { geo: [40.7933949, -77.8600012], type: 'sunset' }, { geo: [40.7933949, -77.8600012], type: 'sunrise', after: thisTimeTomorrow }, { geo: [40.7933949, -77.8600012], type: 'sunset', after: thisTimeTomorrow } ]); resp.forEach(({ collection, error }) => { if (error) { // Handle individual query errors separately, // as some queries may have still succeeded. return console.error(error); } collection.features.forEach(({ properties }) => { console.log(properties); }); }); } catch (ex) { // Handle general network or parsing errors. return console.error(ex); }}; }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });

umpc commented 6 years ago

I can't test this now, though would you try removing the line with the commented require statement?

Expo could be ignoring it while parsing. Just a guess. I will get to this later this week or this weekend.

umpc commented 6 years ago

If this is still an issue, please provide a complete example and I'll be glad to help.

claaslange commented 5 years ago

I have the same problem (albeit with nodejs). Looks like the parser modules tries to export the global location that is only available in browser environments on this line: https://github.com/sunsetwx/sunburst.js/blob/master/src/lib/parsers/params/index.js#L13

umpc commented 5 years ago

@claaslange Thank you for the promising tip. 👍 I will investigate this soon.

umpc commented 5 years ago

@claaslange Let me know if this doesn't fix the issue. A line was missed when we removed a geolocation API before launch.

Thank you for reporting this!

claaslange commented 5 years ago

@umpc works like a charm now 👍 Thanks for the quick fix.